public class code5 {
    public int minNumberOfFrogs(String c) {
        char[] croakOfFrogs = c.toCharArray();
        String t = "croak";//这样字符串进行修改也可以跟着变
        int n = t.length();
        int[] hash = new int[n];//数组模拟哈希表

        Map<Character,Integer> index = new HashMap<>();//为了避免5个if，里面放{x,x这个字符的下标}
        for(int i=0;i<n;i++) {
            index.put(t.charAt(i),i);
        }

        for(char ch:croakOfFrogs) {
            if(ch==t.charAt(0)) {
                if(hash[n-1]!=0) hash[n-1]--;
                hash[0]++;
            }
            else {
                int i = index.get(ch);
                if(hash[i-1]==0) return -1;
                hash[i-1]--;
                hash[i]++;
            }
        }
        for(int i=0;i<n-1;i++) {
            if(hash[i]!=0) return -1;
        }
        return hash[n-1];
    }
}
